package com.exam.demo.interrupt;

import com.exam.demo.service.permissionService.permissionService;
import com.exam.demo.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class LogInterceptor implements HandlerInterceptor {

    @Override
   public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        /*System.out.println("有请求过来了");*/
        String token  = request.getHeader("Authorization");
        if(token == null ){
            System.out.println("请求被拦截，没有token");
            return false;
        } else if (!token.contains("#")) {
            System.out.println("token不符合规则");
            return false;
        }else if(!TokenUtils.validateToken(token.split("#")[1],token.split("#")[0])){
            System.out.println("token无效");
        }
        return true;
    }


}
